// pages/feedback/index.js
import { ShowToast } from "../../utils/async"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Tabs: [
      {
        id: 0,
        name: '意见',
        isactive: true
      },
      {
        id: 1,
        name: '投诉',
        isactive: false
      }
    ],
    image: [],
    inputvalue: ""
  },
  handelactiveTabsClick(e) {


    const { index } = e.detail
    let { Tabs } = this.data
    Tabs.forEach((element, i) => {
      i === index ? element.isactive = true : element.isactive = false
    });
    this.setData({
      Tabs
    })

  },
  handelChooseImg() {
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (result) => {
        const image = result.tempFilePaths
        this.setData({
          image: [...this.data.image, ...image]
        })

      },

    });

  },
  handelRemoveImg(e) {
    const index = e.detail
    const image = this.data.image
    image.splice(index, 1)
    this.setData({
      image
    })

  },
  handleinput(e) {
    const inputvalue = e.detail.value
    this.setData({ inputvalue })

  },

  async handleSubmit() {

    if (this.data.inputvalue.trim().length === 0) {
      await ShowToast("请输入内容")
      return
    } else {
      this.setData({
        inputvalue: "",
        image: []
      })
      await ShowToast("提交成功")
      wx.navigateBack({
        delta: 1
      });
    }
  }

})